package _3_data_struct.list_and_array;

import org.junit.Test;

public class ListVSArray {

  public static void main(String[] args) {

    // 运行时报错, 因为对于数组来说, Long[] 是 Object[] 的 子类
    Object[] objectArray = new Long[1];
    objectArray[0] = "I don't fit in"; // Throws ArrayStoreException

    // 编译时报错, 因为对于 List 来说, List<Long> 不是 List<Object>  的 子类
//    List<Object> ol = new ArrayList<Long>(); // Incompatible types
//    ol.add("I don't fit in");

  }

  @Test
  public void StringArray类型() {
    Object a = new String[]{"test"};
    String b = "test";
    System.out.println(String.valueOf(a.getClass()));
    if (a instanceof String[]) { // 编译时可以判断出来，就会报错，
      System.out.println("hhhh");
    }
  }

  @Test
  public void test() {
    String[] commonVOs = {"1", "2","3","4","5"};
    String[] newCommonVOs = new String[commonVOs.length-1];
    int skipCopy = 4;
    System.arraycopy(commonVOs, 0, newCommonVOs, 0, skipCopy);
    System.arraycopy(commonVOs, skipCopy+1, newCommonVOs, skipCopy, commonVOs.length-skipCopy-1);
    System.out.println(newCommonVOs);
  }
}
